package com.example.demo.response;

import com.google.common.collect.Maps;

import java.util.List;
import java.util.Map;

/**
 * @ClassName: ResultUtil
 * @Description: 返回结果工具类
 * @author: moke
 * @date: 2020/3/17 10:55
 */
public class JsonData {

    public static ResponseData success(Object object){
        ResponseData responseData = new ResponseData();
        responseData.setCode(ResponseCode.SUCCESS.getCode());
        responseData.setMsg(ResponseCode.SUCCESS.getMsg());
        responseData.setData(object);
        return responseData;
    }
    public static ResponseData success(){
        return success(null);
    }
    public static ResponseData fail(Integer code, String message){
        ResponseData responseData = new ResponseData();
        responseData.setCode(code);
        responseData.setMsg(message);
        return responseData;
    }
    public static ResponseData fail(ResponseCode responseCode){
        ResponseData responseData = new ResponseData();
        responseData.setCode(responseCode.getCode());
        responseData.setMsg(responseCode.getMsg());
        return responseData;
    }

    public static ResponseData success(Object object,Long total){

        ResponseData responseData = new ResponseData();
        responseData.setCode(ResponseCode.SUCCESS.getCode());
        responseData.setMsg(ResponseCode.SUCCESS.getMsg());
        responseData.setData(object);
        responseData.setTotal(total);
        return responseData;
    }

    public static ResponseData fail(String message) {
        ResponseData responseData = new ResponseData();
        responseData.setCode(ResponseCode.OPERATE_FAIL.getCode());
        responseData.setMsg(message);
        return responseData;
    }


    /**
     *
     * @param code
     * @param msg
     * @return
     */
    public static Map returnAll(Integer code, String msg) {
        Map map = Maps.newHashMap();
        map.put("code", code);
        map.put("msg", msg);
        return map;
    }

    /**
     * layui 列表返回的map
     *
     * @return
     */
    public static Map returnLayuiMap(List list, Integer count) {
        Map map = Maps.newHashMap();
        map.put("code", 0);
        map.put("msg", "");
        map.put("data", list);
        map.put("count", count);
        return map;
    }
}
